<?php
/**
 * 反垃圾
 * User: wei
 */
class PinkGarbage
{
    private $apiurl;
    private $apis;
    private $action;

    public function __construct($apiurl) {
        $this->apiurl   = $apiurl;
        $this->apis     = array(
            'topic','topic_comment','diary','diary_comment'
        );
    }

    public function execute ($action) {
        if (empty($action)) return false;
        if (!in_array($action, $this->apis)) return false;

        $this->action = $action;
        $result = $this->$action(request());
        return $result;
    }

    /**
     * 话题
     * @param $req
     * @return string
     * @throws Exception
     */
    private function topic()
    {
        $session   = session_id();
        $adminUid  = $_SESSION['user']['adminUid'];
        $index     = '0';
        return render('garbages', array('index' => $index ,'adminUid'=>$adminUid ,'session'=>$session ));
    }

    /**
     * 话题评论
     * @param $req
     * @return string
     * @throws Exception
     */
    private function topic_comment()
    {
        $session   = session_id();
        $adminUid  = $_SESSION['user']['adminUid'];
        $index     = '1';
        return render('garbages', array('index' => $index ,'adminUid'=>$adminUid ,'session'=>$session ));
    }

    /**
     * 日记
     * @param $req
     * @return string
     * @throws Exception
     */
    private function diary()
    {
        $session   = session_id();
        $adminUid  = $_SESSION['user']['adminUid'];
        $index     = '2';
        return render('garbages', array('index' => $index ,'adminUid'=>$adminUid ,'session'=>$session ));
    }

    /**
     * 日记评论
     * @param $req
     * @return string
     * @throws Exception
     */
    private function diary_comment()
    {
        $session   = session_id();
        $adminUid  = $_SESSION['user']['adminUid'];
        $index     = '3';
        return render('garbages', array('index' => $index ,'adminUid'=>$adminUid ,'session'=>$session ));
    }


}

$req = request();
$PinkGarbage   = new PinkGarbage($_SC ['apiurl']);
echo $PinkGarbage->execute($req['op']);






